package com.example.myapplication.db

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.room.util.newStringBuilder
import retrofit2.Response

class Repository(private val userDao: UserDao) {
    suspend fun saveUser(user: User){
        Log.d("Repository", "User saved: ${user.account}")
        Log.d("Repository", "User saved: ${user.password}")
        userDao.insertUser(user)
    }

    suspend fun deleteUser(user: User){
        userDao.deleteUser(user)
    }

    suspend fun deleteAll(){
        userDao.deleteAll()
    }

    suspend fun updateUser(user: User){
        userDao.updateUser(user)
    }

    suspend fun  updateUserCreditRating(id:Int,newRating:Int){
        userDao.updateCreditRating(id,newRating)
    }

    suspend fun  updateReward(id:Int,newReward:String){
        userDao.updateReward(id,newReward)
    }

    suspend fun  updateNewSelfIntroduction(id:Int,newSelfIntroduction:String){
        userDao.updateSelfIntroduction(id, newSelfIntroduction)
    }


    fun loadUsers(): LiveData<List<User>> {
        Log.d("Repository", "Loading users from database")
        return userDao.loadUsers()
    }


}